package com.jt.tenant.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetIntegral;
import com.jt.tenant.widget.Tools;
import com.zcx.helper.http.AsyCallBack;

/**
 * Created by AD on 2016/5/23.
 */
public class IntegralActivity extends JTActivity implements OnClickListener {

    private TextView mTitleName;

    private TextView tv_integral_get;

    private LinearLayout lin_integral_details_ty,lin_integral_details_dx;

    private TextView tv_integral_total,tv_integral_ty,tv_integral_dx,tv_integral_total_today;

    private GetIntegral getIntegral = new GetIntegral(new AsyCallBack<GetIntegral.Info>(){

        @Override
        public void onSuccess(String toast, int type, GetIntegral.Info info) throws Exception {

            super.onSuccess(toast, type, info);

            tv_integral_total.setText(Tools.F_num(String.valueOf(Double.parseDouble(info.integralCount)+Double.parseDouble(info.commonCount)))+"分");

            tv_integral_ty.setText(""+info.commonCount+"分");

            JTApplication.jtPreferences.saveUserIntegral(info.commonCount,"2");

            tv_integral_dx.setText(""+info.integralCount+"分");

            JTApplication.jtPreferences.saveUserIntegral(info.integralCount,"1");

            tv_integral_total_today.setText(info.todayCount+"分");

        }
    });


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_integral);

        initView();
        GetData();
    }

    private void initView() {

        (mTitleName = (TextView)findViewById(R.id.tv_title_name) ).setText("我的积分");

        (tv_integral_get = (TextView) findViewById(R.id.tv_integral_get)).setOnClickListener(this);

        (lin_integral_details_ty = (LinearLayout)findViewById(R.id.lin_integral_details_ty)).setOnClickListener(this);

        (lin_integral_details_dx = (LinearLayout)findViewById(R.id.lin_integral_details_dx)).setOnClickListener(this);

        tv_integral_total = (TextView)findViewById(R.id.tv_integral_total);

        tv_integral_ty = (TextView)findViewById(R.id.tv_integral_ty);

        tv_integral_ty.setText(""+JTApplication.jtPreferences.readUserIntegral("2"));

        tv_integral_dx = (TextView)findViewById(R.id.tv_integral_dx);

        tv_integral_dx.setText(""+JTApplication.jtPreferences.readUserIntegral("1"));

        tv_integral_total_today = (TextView)findViewById(R.id.tv_integral_total_today);

        getIntegral.execute(this);

    }
    private void GetData(){


    }

    public void onClick(View v) {

        switch (v.getId()){

            //通用积分
            case R.id.lin_integral_details_ty:

                startActivity(new Intent(this, IntegralInfoActivity.class).putExtra("flag","2"));

                break;

            //定向积分
            case R.id.lin_integral_details_dx:

                startActivity(new Intent(this, IntegralInfoActivity.class).putExtra("flag","1"));

                break;

            //如何获得积分
            case R.id.tv_integral_get:

                startActivity(new Intent(this, AgreementActivity.class)

                        .putExtra("id","4")

                        .putExtra("title","如何获得积分")

                );

                break;





        }
    }


}
